package com.free.chat.web;

import com.free.chat.entity.ApiResult;
import com.free.chat.entity.dto.ChatMsgDTO;
import com.free.chat.entity.model.ChatMsg;
import com.free.chat.service.ChatMsgService;
import io.swagger.annotations.Api;
import org.noear.solon.annotation.*;

/**
 * (ChatMsg)表控制层
 *
 * @author makejava
 * @since 2022-10-21 20:00:03
 */
@Controller
@Mapping("chatMsg")
@Api(tags = "聊天接口")
public class ChatMsgController {
    /**
     * 服务对象
     */
    @Inject
    private ChatMsgService chatMsgService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Get
    @Mapping("queryById")
    public ApiResult queryById(Long id) {
        return ApiResult.success(this.chatMsgService.queryById(id));
    }

    @Get
    @Mapping("list")
    public ApiResult list(ChatMsgDTO chatMsgDTO) {
        return chatMsgService.list(chatMsgDTO);
    }

    /**
     * 新增数据
     *
     * @param chatMsg 实体
     * @return 新增结果
     */
    @Post
    @Mapping("add")
    public ApiResult add(ChatMsg chatMsg) {
        return ApiResult.success(this.chatMsgService.insert(chatMsg));
    }

    /**
     * 编辑数据
     *
     * @param chatMsg 实体
     * @return 编辑结果
     */
    @Post
    @Mapping("edit")
    public ApiResult edit(ChatMsg chatMsg) {
        return ApiResult.success(this.chatMsgService.update(chatMsg));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Get
    @Mapping("deleteById")
    public ApiResult deleteById(Long id) {
        return ApiResult.success(this.chatMsgService.deleteById(id));
    }

    @Get
    @Mapping("getChatMsgByAcceptUserId")
    public ApiResult getChatMsgByAcceptUserId(ChatMsgDTO chatMsgDTO) {
        return chatMsgService.getChatMsgByAcceptUserId(chatMsgDTO);
    }
}

